package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 查看userinfo表中一共多少条记录?
 *
 * SELECT COUNT(*) FROM userinfo
 */
public class JDBCDemo10 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            String sql = "SELECT COUNT(*) count FROM userinfo";
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            if(rs.next()){
                int count = rs.getInt("count");
                System.out.println("一共"+count+"条记录");
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
